package com.itheima.controller;


import com.itheima.pojo.Brand;
import com.itheima.service.BrandService;
import com.itheima.util.PageResult;
import com.itheima.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    //2022.1.8  分页查询
    @GetMapping("/search/{page}/{size}")
    public Result findPage(@PathVariable int page, @PathVariable int size){
        PageResult pr = brandService.findPage(page,size);
        return new Result(0,true,"查询成功",pr);
    }
    //2022.1.8  查询Brand全部列表
    @GetMapping
    public Result findAll(){
        List<Brand> list =  brandService.findAll();
       return new Result(0,true,"查询成功",list);
    }


    @PutMapping
    public Result update(@RequestBody Brand brand){
        brandService.update(brand);
        return new Result(0,true,"删除成功",null);
    }

    @GetMapping("/search")
    public Result findList(String search){
       return brandService.findList(search);
    }


    @DeleteMapping("/{brandId}")
    public Result delete(@PathVariable String brandId){
        brandService.delete(brandId);
        return new Result(0,true,"删除成功",null);
    }

        @PostMapping("/add")
    public Result add(@RequestBody Brand brand){
        return brandService.add(brand);
    }
    
    @GetMapping("/{brandId}")
    public Result findById(@PathVariable Integer brandId){
        return brandService.findById(brandId);
    }

}
